﻿using System;

namespace demo7
{
    class Program
    {
        static void Main(string[] args)
        {
            /* 局部变量定义 */
            int a = 10;

            /* while 循环执行 */
            while (a < 20)
            {
                Console.WriteLine("a 的值： {0}", a);
                a++;
            }
            Console.ReadLine();

            /* for 循环执行 */
            for (int b = 10; b < 20; b = b + 1)
            {
                Console.WriteLine("b 的值： {0}", b);
            }
            Console.ReadLine();

            // foreach 循环
            int[] fibarray = new int[] { 0, 1, 1, 2, 3, 5, 8, 13 };
            foreach (int element in fibarray)
            {
                System.Console.WriteLine (element);
            }
            System.Console.WriteLine();

            // 类似 foreach 循环
            for (int i = 0; i < fibarray.Length; i++)
            {
                System.Console.WriteLine(fibarray[i]);
            }
            System.Console.WriteLine();

            // 设置集合中元素的计算器
            int count = 0;
            foreach (int element in fibarray)
            {
                count += 1;
                System.Console.WriteLine("Element #{0}: {1}", count, element);
            }
            System
                .Console
                .WriteLine("Number of elements in the array: {0}", count);

            // do...while循环
            /* 局部变量定义 */
            int c = 10;

            /* do 循环执行 */
            do
            {
                Console.WriteLine("c 的值： {0}", c);
                c = c + 1;
            }
            while (c < 20);

            Console.ReadLine();
        }
    }
}
